package com.hyt.it.ogt.kq.main.controller.gov;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.gov.model.entity.Dict;
import com.hyt.it.ogt.kq.service.gov.service.GovIDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据字典接口
 *
 * @author liuhh
 * @since 2022-08-01
 */
@RestController
@Api(tags = "135.数据字典接口", value = "数据字典接口")
@ApiSort(value = 135)
@RequestMapping("/kw/gov/dict")
@Slf4j
public class GovDictController extends BaseController {
    @Resource
    private GovIDictService iDictService;

    @ApiOperation(value = "35.1 根据类型查询数据字典")
    @ApiOperationSort(value = 1)
    @GetMapping("/getByType")
    public ApiResponse<List<Dict>> getByType(String type) {
        try {
            List<Dict> list = iDictService.lambdaQuery().select(Dict::getValue, Dict::getLabel)
                    .eq(Dict::getType, type).eq(Dict::getDelFlag, false).orderByAsc(Dict::getSort).list();
            return ApiResponse.<List<Dict>>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("# 根据类型查询数据字典异常: ", e);
            return ApiResponse.<List<Dict>>builder().build();
        }
    }
}
